package com.hc.bankonline.servlet;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hc.bankonline.services.BankOnlineservices;
import com.hc.bankonline.services.BankOnlineservicesImpl;

public class BankOnlineTransferServlet extends HttpServlet {

	private static final long serialVersionUID = -7283383395325592657L;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		
		Map map = (Map)  request.getSession().getAttribute("mapAcount");
		
		
		String loginAccount =(String) map.get("loginAccount");
		
		String cardno = request.getParameter("cardno");
		String i = request.getParameter("money");
		if(i == null){
			i = "0";
		}
		int money = Integer.valueOf(i);
		
		BankOnlineservices bankOnlineBiz = new BankOnlineservicesImpl();
		
		boolean result = bankOnlineBiz.transferAddInfo(cardno,money);
		boolean result1 = bankOnlineBiz.transferDelInfo(loginAccount, money);
		
		if(result && result1){
			System.out.println("转账成功!");
			request.getRequestDispatcher("transfersuccess.jsp").forward(request,response);
		}else{
			System.out.println("转账失败!");
			request.getRequestDispatcher("transfer.jsp").forward(request,response);
		}
		
		
		
	}

}
